﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="VwObracunZaIDPorezPrirezProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class VwObracunZaIDPorezPrirezProviderBaseCore : EntityViewProviderBase<VwObracunZaIDPorezPrirez>
	{
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;VwObracunZaIDPorezPrirez&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;VwObracunZaIDPorezPrirez&gt;"/></returns>
		protected static VList&lt;VwObracunZaIDPorezPrirez&gt; Fill(DataSet dataSet, VList<VwObracunZaIDPorezPrirez> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<VwObracunZaIDPorezPrirez>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;VwObracunZaIDPorezPrirez&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<VwObracunZaIDPorezPrirez>"/></returns>
		protected static VList&lt;VwObracunZaIDPorezPrirez&gt; Fill(DataTable dataTable, VList<VwObracunZaIDPorezPrirez> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					VwObracunZaIDPorezPrirez c = new VwObracunZaIDPorezPrirez();
					c.IDObracun = (Convert.IsDBNull(row["IDObracun"]))?(int)0:(System.Int32)row["IDObracun"];
					c.Mjesto = (Convert.IsDBNull(row["Mjesto"]))?string.Empty:(System.String)row["Mjesto"];
					c.SifraOpcine = (Convert.IsDBNull(row["SifraOpcine"]))?(int)0:(System.Int32?)row["SifraOpcine"];
					c.PorezIznos = (Convert.IsDBNull(row["PorezIznos"]))?0:(System.Decimal?)row["PorezIznos"];
					c.PrirezIznos = (Convert.IsDBNull(row["PrirezIznos"]))?0:(System.Decimal?)row["PrirezIznos"];
					c.Ukupno = (Convert.IsDBNull(row["Ukupno"]))?0:(System.Decimal?)row["Ukupno"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;VwObracunZaIDPorezPrirez&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;VwObracunZaIDPorezPrirez&gt;"/></returns>
		protected VList<VwObracunZaIDPorezPrirez> Fill(IDataReader reader, VList<VwObracunZaIDPorezPrirez> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					VwObracunZaIDPorezPrirez entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<VwObracunZaIDPorezPrirez>("VwObracunZaIDPorezPrirez",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new VwObracunZaIDPorezPrirez();
					}
					entity.IDObracun = (System.Int32)reader["IDObracun"];
					//entity.IDObracun = (Convert.IsDBNull(reader["IDObracun"]))?(int)0:(System.Int32)reader["IDObracun"];
					entity.Mjesto = (System.String)reader["Mjesto"];
					//entity.Mjesto = (Convert.IsDBNull(reader["Mjesto"]))?string.Empty:(System.String)reader["Mjesto"];
					entity.SifraOpcine = reader.IsDBNull(reader.GetOrdinal("SifraOpcine")) ? null : (System.Int32?)reader["SifraOpcine"];
					//entity.SifraOpcine = (Convert.IsDBNull(reader["SifraOpcine"]))?(int)0:(System.Int32?)reader["SifraOpcine"];
					entity.PorezIznos = reader.IsDBNull(reader.GetOrdinal("PorezIznos")) ? null : (System.Decimal?)reader["PorezIznos"];
					//entity.PorezIznos = (Convert.IsDBNull(reader["PorezIznos"]))?0:(System.Decimal?)reader["PorezIznos"];
					entity.PrirezIznos = reader.IsDBNull(reader.GetOrdinal("PrirezIznos")) ? null : (System.Decimal?)reader["PrirezIznos"];
					//entity.PrirezIznos = (Convert.IsDBNull(reader["PrirezIznos"]))?0:(System.Decimal?)reader["PrirezIznos"];
					entity.Ukupno = reader.IsDBNull(reader.GetOrdinal("Ukupno")) ? null : (System.Decimal?)reader["Ukupno"];
					//entity.Ukupno = (Convert.IsDBNull(reader["Ukupno"]))?0:(System.Decimal?)reader["Ukupno"];
					entity.AcceptChanges();
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="VwObracunZaIDPorezPrirez"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VwObracunZaIDPorezPrirez"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, VwObracunZaIDPorezPrirez entity)
		{
			reader.Read();
			entity.IDObracun = (System.Int32)reader["IDObracun"];
			//entity.IDObracun = (Convert.IsDBNull(reader["IDObracun"]))?(int)0:(System.Int32)reader["IDObracun"];
			entity.Mjesto = (System.String)reader["Mjesto"];
			//entity.Mjesto = (Convert.IsDBNull(reader["Mjesto"]))?string.Empty:(System.String)reader["Mjesto"];
			entity.SifraOpcine = reader.IsDBNull(reader.GetOrdinal("SifraOpcine")) ? null : (System.Int32?)reader["SifraOpcine"];
			//entity.SifraOpcine = (Convert.IsDBNull(reader["SifraOpcine"]))?(int)0:(System.Int32?)reader["SifraOpcine"];
			entity.PorezIznos = reader.IsDBNull(reader.GetOrdinal("PorezIznos")) ? null : (System.Decimal?)reader["PorezIznos"];
			//entity.PorezIznos = (Convert.IsDBNull(reader["PorezIznos"]))?0:(System.Decimal?)reader["PorezIznos"];
			entity.PrirezIznos = reader.IsDBNull(reader.GetOrdinal("PrirezIznos")) ? null : (System.Decimal?)reader["PrirezIznos"];
			//entity.PrirezIznos = (Convert.IsDBNull(reader["PrirezIznos"]))?0:(System.Decimal?)reader["PrirezIznos"];
			entity.Ukupno = reader.IsDBNull(reader.GetOrdinal("Ukupno")) ? null : (System.Decimal?)reader["Ukupno"];
			//entity.Ukupno = (Convert.IsDBNull(reader["Ukupno"]))?0:(System.Decimal?)reader["Ukupno"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="VwObracunZaIDPorezPrirez"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VwObracunZaIDPorezPrirez"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, VwObracunZaIDPorezPrirez entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.IDObracun = (Convert.IsDBNull(dataRow["IDObracun"]))?(int)0:(System.Int32)dataRow["IDObracun"];
			entity.Mjesto = (Convert.IsDBNull(dataRow["Mjesto"]))?string.Empty:(System.String)dataRow["Mjesto"];
			entity.SifraOpcine = (Convert.IsDBNull(dataRow["SifraOpcine"]))?(int)0:(System.Int32?)dataRow["SifraOpcine"];
			entity.PorezIznos = (Convert.IsDBNull(dataRow["PorezIznos"]))?0:(System.Decimal?)dataRow["PorezIznos"];
			entity.PrirezIznos = (Convert.IsDBNull(dataRow["PrirezIznos"]))?0:(System.Decimal?)dataRow["PrirezIznos"];
			entity.Ukupno = (Convert.IsDBNull(dataRow["Ukupno"]))?0:(System.Decimal?)dataRow["Ukupno"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region VwObracunZaIDPorezPrirezFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwObracunZaIDPorezPrirez"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwObracunZaIDPorezPrirezFilterBuilder : SqlFilterBuilder<VwObracunZaIDPorezPrirezColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwObracunZaIDPorezPrirezFilterBuilder class.
		/// </summary>
		public VwObracunZaIDPorezPrirezFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwObracunZaIDPorezPrirezFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwObracunZaIDPorezPrirezFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwObracunZaIDPorezPrirezFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwObracunZaIDPorezPrirezFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwObracunZaIDPorezPrirezFilterBuilder

	#region VwObracunZaIDPorezPrirezParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwObracunZaIDPorezPrirez"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwObracunZaIDPorezPrirezParameterBuilder : ParameterizedSqlFilterBuilder<VwObracunZaIDPorezPrirezColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwObracunZaIDPorezPrirezParameterBuilder class.
		/// </summary>
		public VwObracunZaIDPorezPrirezParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwObracunZaIDPorezPrirezParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwObracunZaIDPorezPrirezParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwObracunZaIDPorezPrirezParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwObracunZaIDPorezPrirezParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwObracunZaIDPorezPrirezParameterBuilder
} // end namespace
